package com.hbnu.commonclass;

public class Animal {
    public String name;

    public int age;
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString(){
        return "Animal:{name:"+this.name+" age:"+this.age+"}";
    }


    @Override
    public boolean equals(Object object){
        if (object == null){
            return false;
        }
        if (this == object){
            return true;
        }
        if (!(object instanceof Animal)){ //如果传入的对象和当前对象不算同一类型，则直接返回false
            return false;
        }
        Animal animal = (Animal) object;    //类型强转：将传入的对象转为当前对象类型


        return this.age == animal.age && this.name.equals(animal.name);


    }
}
